package com.ruoyi.loginfo.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loginfo.domain.LogTrack;
import com.ruoyi.loginfo.service.ILogTrackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物流轨迹Controller
 *
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/track")
public class LogTrackController extends BaseController {
    @Autowired
    private ILogTrackService logTrackService;

    /**
     * 查询物流轨迹列表
     */
    @RequiresPermissions("loginfo:track:list")
    @GetMapping("/list")
    public TableDataInfo list(LogTrack logTrack) {
        startPage();
        List<LogTrack> list = logTrackService.selectLogTrackList(logTrack);
        return getDataTable(list);
    }

    /**
     * 导出物流轨迹列表
     */
    @RequiresPermissions("loginfo:track:export")
    @Log(title = "物流轨迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogTrack logTrack) {
        List<LogTrack> list = logTrackService.selectLogTrackList(logTrack);
        ExcelUtil<LogTrack> util = new ExcelUtil<LogTrack>(LogTrack.class);
        util.exportExcel(response, list, "物流轨迹数据");
    }

    /**
     * 获取物流轨迹详细信息
     */
    @RequiresPermissions("loginfo:track:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(logTrackService.selectLogTrackById(id));
    }

    /**
     * 获取物流轨迹详细信息
     */
    @RequiresPermissions("loginfo:track:query")
    @GetMapping(value = "/orderId/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Long id) {
        System.out.println("sadwa="+id);
        return success(logTrackService.selectLogTrackByLogisticsInfoId(id));
    }

    /**
     * 新增物流轨迹
     */
    @RequiresPermissions("loginfo:track:add")
    @Log(title = "物流轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogTrack logTrack) {
        return toAjax(logTrackService.insertLogTrack(logTrack));
    }

    /**
     * 修改物流轨迹
     */
    @RequiresPermissions("loginfo:track:edit")
    @Log(title = "物流轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogTrack logTrack) {
        return toAjax(logTrackService.updateLogTrack(logTrack));
    }

    /**
     * 删除物流轨迹
     */
    @RequiresPermissions("loginfo:track:remove")
    @Log(title = "物流轨迹", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(logTrackService.deleteLogTrackByIds(ids));
    }
}
